﻿using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using EB.Math;

namespace Viet_Calculator
{
	/// <summary>
	/// Summary description for MayTinhBieuThuc.
	/// </summary>
	public class MayTinhBieuThuc : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.GroupBox groupBox4;
		private System.Windows.Forms.TextBox txtKetQua;
		private System.Windows.Forms.TextBox txtGoBieuThuc;
		private System.Windows.Forms.GroupBox groupBox5;
		private System.Windows.Forms.RadioButton rdbDo;
		private System.Windows.Forms.RadioButton rdbRadian;
		private System.Windows.Forms.GroupBox groupBox6;
		private System.Windows.Forms.Button btnCong;
		private System.Windows.Forms.Button btnTru;
		private System.Windows.Forms.Button btnNhan;
		private System.Windows.Forms.Button btnChia;
		private System.Windows.Forms.Button btnSoDu;
		private System.Windows.Forms.Button btnMu;
		private System.Windows.Forms.Button btnNgoacDonTrai;
		private System.Windows.Forms.Button btnNgoacDonPhai;
		private System.Windows.Forms.Button btnNgoacVuongTrai;
		private System.Windows.Forms.Button btnNgoacVuongPhai;
		private System.Windows.Forms.Button btnNgoacNhonTrai;
		private System.Windows.Forms.Button btnNgoacNhonPhai;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button btnThem;
		private System.Windows.Forms.Button btnXoaHet;
		private System.Windows.Forms.Button btnE;
		private System.Windows.Forms.Button btnPi;
		private System.Windows.Forms.Button btnDauChamThapPhan;
		private System.Windows.Forms.Button btnSo9;
		private System.Windows.Forms.Button btnSo8;
		private System.Windows.Forms.Button btnSo7;
		private System.Windows.Forms.Button btnSo6;
		private System.Windows.Forms.Button btnSo5;
		private System.Windows.Forms.Button btnSo4;
		private System.Windows.Forms.Button btnSo3;
		private System.Windows.Forms.Button btnSo2;
		private System.Windows.Forms.Button btnSo1;
		private System.Windows.Forms.Button btnSo0;
		private System.Windows.Forms.Button btnSo00;
		private System.Windows.Forms.Button btnSo000;
		private System.Windows.Forms.Button btnThongTin;
		private System.Windows.Forms.Button btnGiai;
		private System.Windows.Forms.ListBox lbHam;
		private DataSet m_dataSet = new DataSet("DataSet");
		private DataTable m_table = new DataTable("Variable");
		private Y_Function fn = new Y_Function();
		private System.Windows.Forms.DataGrid m_symTable;
		private System.Windows.Forms.Button btnPhanTich;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public MayTinhBieuThuc()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
			DataColumn name = new DataColumn("Ten", typeof(string));
			DataColumn ddValue = new DataColumn("Gia tri",typeof(double));
			name.ReadOnly = true;
			name.AllowDBNull = false;
			m_table.Columns.Add(name);
			m_table.Columns.Add(ddValue);
			m_dataSet.Tables.Add(m_table);
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MayTinhBieuThuc));
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.label1 = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.groupBox6 = new System.Windows.Forms.GroupBox();
			this.m_symTable = new System.Windows.Forms.DataGrid();
			this.btnThongTin = new System.Windows.Forms.Button();
			this.btnThem = new System.Windows.Forms.Button();
			this.btnXoaHet = new System.Windows.Forms.Button();
			this.btnE = new System.Windows.Forms.Button();
			this.btnPi = new System.Windows.Forms.Button();
			this.btnDauChamThapPhan = new System.Windows.Forms.Button();
			this.btnSo9 = new System.Windows.Forms.Button();
			this.btnSo8 = new System.Windows.Forms.Button();
			this.btnSo7 = new System.Windows.Forms.Button();
			this.btnSo6 = new System.Windows.Forms.Button();
			this.btnSo5 = new System.Windows.Forms.Button();
			this.btnSo4 = new System.Windows.Forms.Button();
			this.btnSo3 = new System.Windows.Forms.Button();
			this.btnSo2 = new System.Windows.Forms.Button();
			this.btnSo1 = new System.Windows.Forms.Button();
			this.btnSo0 = new System.Windows.Forms.Button();
			this.btnSo00 = new System.Windows.Forms.Button();
			this.btnSo000 = new System.Windows.Forms.Button();
			this.btnNgoacNhonPhai = new System.Windows.Forms.Button();
			this.btnNgoacNhonTrai = new System.Windows.Forms.Button();
			this.btnNgoacVuongPhai = new System.Windows.Forms.Button();
			this.btnNgoacVuongTrai = new System.Windows.Forms.Button();
			this.btnNgoacDonPhai = new System.Windows.Forms.Button();
			this.btnNgoacDonTrai = new System.Windows.Forms.Button();
			this.btnMu = new System.Windows.Forms.Button();
			this.btnSoDu = new System.Windows.Forms.Button();
			this.btnChia = new System.Windows.Forms.Button();
			this.btnNhan = new System.Windows.Forms.Button();
			this.btnTru = new System.Windows.Forms.Button();
			this.btnCong = new System.Windows.Forms.Button();
			this.groupBox5 = new System.Windows.Forms.GroupBox();
			this.btnPhanTich = new System.Windows.Forms.Button();
			this.btnGiai = new System.Windows.Forms.Button();
			this.rdbRadian = new System.Windows.Forms.RadioButton();
			this.rdbDo = new System.Windows.Forms.RadioButton();
			this.txtKetQua = new System.Windows.Forms.TextBox();
			this.txtGoBieuThuc = new System.Windows.Forms.TextBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.lbHam = new System.Windows.Forms.ListBox();
			this.groupBox1.SuspendLayout();
			this.groupBox2.SuspendLayout();
			this.groupBox4.SuspendLayout();
			this.groupBox6.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.m_symTable)).BeginInit();
			this.groupBox5.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(616, 96);
			this.groupBox1.TabIndex = 0;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "Hướng dẫn";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(600, 64);
			this.label1.TabIndex = 0;
			this.label1.Text = @"Các bạn có thể dùng chuột và bàn phím để nhập giá trị vào ô trống. Các bạn hãy kích chuột vào nút Thêm nếu các bạn muốn thêm những hàm như sin, cos... vào ô trống. Nếu các bạn muốn xóa hết giá trị trong ô trống các bạn làm ơn kích chuột vào nút Xóa hết hoặc sử dụng bàn phím. Các bạn nhớ viết liền nhé. Ví dụ: sin(30)+2 chứ không phải là sin(30) + 2";
			// 
			// groupBox2
			// 
			this.groupBox2.Controls.Add(this.groupBox4);
			this.groupBox2.Controls.Add(this.groupBox3);
			this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox2.Location = new System.Drawing.Point(9, 112);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(615, 368);
			this.groupBox2.TabIndex = 1;
			this.groupBox2.TabStop = false;
			// 
			// groupBox4
			// 
			this.groupBox4.Controls.Add(this.groupBox6);
			this.groupBox4.Controls.Add(this.groupBox5);
			this.groupBox4.Controls.Add(this.txtKetQua);
			this.groupBox4.Controls.Add(this.txtGoBieuThuc);
			this.groupBox4.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox4.Location = new System.Drawing.Point(16, 16);
			this.groupBox4.Name = "groupBox4";
			this.groupBox4.Size = new System.Drawing.Size(448, 344);
			this.groupBox4.TabIndex = 3;
			this.groupBox4.TabStop = false;
			// 
			// groupBox6
			// 
			this.groupBox6.Controls.Add(this.m_symTable);
			this.groupBox6.Controls.Add(this.btnThongTin);
			this.groupBox6.Controls.Add(this.btnThem);
			this.groupBox6.Controls.Add(this.btnXoaHet);
			this.groupBox6.Controls.Add(this.btnE);
			this.groupBox6.Controls.Add(this.btnPi);
			this.groupBox6.Controls.Add(this.btnDauChamThapPhan);
			this.groupBox6.Controls.Add(this.btnSo9);
			this.groupBox6.Controls.Add(this.btnSo8);
			this.groupBox6.Controls.Add(this.btnSo7);
			this.groupBox6.Controls.Add(this.btnSo6);
			this.groupBox6.Controls.Add(this.btnSo5);
			this.groupBox6.Controls.Add(this.btnSo4);
			this.groupBox6.Controls.Add(this.btnSo3);
			this.groupBox6.Controls.Add(this.btnSo2);
			this.groupBox6.Controls.Add(this.btnSo1);
			this.groupBox6.Controls.Add(this.btnSo0);
			this.groupBox6.Controls.Add(this.btnSo00);
			this.groupBox6.Controls.Add(this.btnSo000);
			this.groupBox6.Controls.Add(this.btnNgoacNhonPhai);
			this.groupBox6.Controls.Add(this.btnNgoacNhonTrai);
			this.groupBox6.Controls.Add(this.btnNgoacVuongPhai);
			this.groupBox6.Controls.Add(this.btnNgoacVuongTrai);
			this.groupBox6.Controls.Add(this.btnNgoacDonPhai);
			this.groupBox6.Controls.Add(this.btnNgoacDonTrai);
			this.groupBox6.Controls.Add(this.btnMu);
			this.groupBox6.Controls.Add(this.btnSoDu);
			this.groupBox6.Controls.Add(this.btnChia);
			this.groupBox6.Controls.Add(this.btnNhan);
			this.groupBox6.Controls.Add(this.btnTru);
			this.groupBox6.Controls.Add(this.btnCong);
			this.groupBox6.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox6.Location = new System.Drawing.Point(16, 144);
			this.groupBox6.Name = "groupBox6";
			this.groupBox6.Size = new System.Drawing.Size(416, 192);
			this.groupBox6.TabIndex = 5;
			this.groupBox6.TabStop = false;
			// 
			// m_symTable
			// 
			this.m_symTable.DataMember = "";
			this.m_symTable.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.m_symTable.Location = new System.Drawing.Point(16, 104);
			this.m_symTable.Name = "m_symTable";
			this.m_symTable.Size = new System.Drawing.Size(384, 72);
			this.m_symTable.TabIndex = 30;
			// 
			// btnThongTin
			// 
			this.btnThongTin.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnThongTin.Location = new System.Drawing.Point(208, 72);
			this.btnThongTin.Name = "btnThongTin";
			this.btnThongTin.Size = new System.Drawing.Size(64, 24);
			this.btnThongTin.TabIndex = 29;
			this.btnThongTin.Text = "@";
			this.btnThongTin.Click += new System.EventHandler(this.btnThongTin_Click);
			// 
			// btnThem
			// 
			this.btnThem.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnThem.Location = new System.Drawing.Point(336, 72);
			this.btnThem.Name = "btnThem";
			this.btnThem.Size = new System.Drawing.Size(64, 24);
			this.btnThem.TabIndex = 28;
			this.btnThem.Text = "Thêm";
			this.btnThem.Click += new System.EventHandler(this.btnThem_Click);
			// 
			// btnXoaHet
			// 
			this.btnXoaHet.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnXoaHet.Location = new System.Drawing.Point(272, 72);
			this.btnXoaHet.Name = "btnXoaHet";
			this.btnXoaHet.Size = new System.Drawing.Size(64, 24);
			this.btnXoaHet.TabIndex = 27;
			this.btnXoaHet.Text = "Xóa hết";
			this.btnXoaHet.Click += new System.EventHandler(this.btnXoaHet_Click);
			// 
			// btnE
			// 
			this.btnE.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnE.Location = new System.Drawing.Point(176, 72);
			this.btnE.Name = "btnE";
			this.btnE.Size = new System.Drawing.Size(32, 24);
			this.btnE.TabIndex = 26;
			this.btnE.Text = "e";
			this.btnE.Click += new System.EventHandler(this.btnE_Click);
			// 
			// btnPi
			// 
			this.btnPi.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnPi.Location = new System.Drawing.Point(144, 72);
			this.btnPi.Name = "btnPi";
			this.btnPi.Size = new System.Drawing.Size(32, 24);
			this.btnPi.TabIndex = 25;
			this.btnPi.Text = "pi";
			this.btnPi.Click += new System.EventHandler(this.btnPi_Click);
			// 
			// btnDauChamThapPhan
			// 
			this.btnDauChamThapPhan.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnDauChamThapPhan.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnDauChamThapPhan.Location = new System.Drawing.Point(16, 72);
			this.btnDauChamThapPhan.Name = "btnDauChamThapPhan";
			this.btnDauChamThapPhan.Size = new System.Drawing.Size(32, 24);
			this.btnDauChamThapPhan.TabIndex = 24;
			this.btnDauChamThapPhan.Text = ".";
			this.btnDauChamThapPhan.Click += new System.EventHandler(this.btnDauChamThapPhan_Click);
			// 
			// btnSo9
			// 
			this.btnSo9.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo9.Location = new System.Drawing.Point(336, 48);
			this.btnSo9.Name = "btnSo9";
			this.btnSo9.Size = new System.Drawing.Size(32, 24);
			this.btnSo9.TabIndex = 23;
			this.btnSo9.Text = "9";
			this.btnSo9.Click += new System.EventHandler(this.btnSo9_Click);
			// 
			// btnSo8
			// 
			this.btnSo8.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo8.Location = new System.Drawing.Point(304, 48);
			this.btnSo8.Name = "btnSo8";
			this.btnSo8.Size = new System.Drawing.Size(32, 24);
			this.btnSo8.TabIndex = 22;
			this.btnSo8.Text = "8";
			this.btnSo8.Click += new System.EventHandler(this.btnSo8_Click);
			// 
			// btnSo7
			// 
			this.btnSo7.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo7.Location = new System.Drawing.Point(272, 48);
			this.btnSo7.Name = "btnSo7";
			this.btnSo7.Size = new System.Drawing.Size(32, 24);
			this.btnSo7.TabIndex = 21;
			this.btnSo7.Text = "7";
			this.btnSo7.Click += new System.EventHandler(this.btnSo7_Click);
			// 
			// btnSo6
			// 
			this.btnSo6.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo6.Location = new System.Drawing.Point(240, 48);
			this.btnSo6.Name = "btnSo6";
			this.btnSo6.Size = new System.Drawing.Size(32, 24);
			this.btnSo6.TabIndex = 20;
			this.btnSo6.Text = "6";
			this.btnSo6.Click += new System.EventHandler(this.btnSo6_Click);
			// 
			// btnSo5
			// 
			this.btnSo5.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo5.Location = new System.Drawing.Point(208, 48);
			this.btnSo5.Name = "btnSo5";
			this.btnSo5.Size = new System.Drawing.Size(32, 24);
			this.btnSo5.TabIndex = 19;
			this.btnSo5.Text = "5";
			this.btnSo5.Click += new System.EventHandler(this.btnSo5_Click);
			// 
			// btnSo4
			// 
			this.btnSo4.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo4.Location = new System.Drawing.Point(176, 48);
			this.btnSo4.Name = "btnSo4";
			this.btnSo4.Size = new System.Drawing.Size(32, 24);
			this.btnSo4.TabIndex = 18;
			this.btnSo4.Text = "4";
			this.btnSo4.Click += new System.EventHandler(this.btnSo4_Click);
			// 
			// btnSo3
			// 
			this.btnSo3.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo3.Location = new System.Drawing.Point(144, 48);
			this.btnSo3.Name = "btnSo3";
			this.btnSo3.Size = new System.Drawing.Size(32, 24);
			this.btnSo3.TabIndex = 17;
			this.btnSo3.Text = "3";
			this.btnSo3.Click += new System.EventHandler(this.btnSo3_Click);
			// 
			// btnSo2
			// 
			this.btnSo2.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo2.Location = new System.Drawing.Point(112, 48);
			this.btnSo2.Name = "btnSo2";
			this.btnSo2.Size = new System.Drawing.Size(32, 24);
			this.btnSo2.TabIndex = 16;
			this.btnSo2.Text = "2";
			this.btnSo2.Click += new System.EventHandler(this.btnSo2_Click);
			// 
			// btnSo1
			// 
			this.btnSo1.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo1.Location = new System.Drawing.Point(80, 48);
			this.btnSo1.Name = "btnSo1";
			this.btnSo1.Size = new System.Drawing.Size(32, 24);
			this.btnSo1.TabIndex = 15;
			this.btnSo1.Text = "1";
			this.btnSo1.Click += new System.EventHandler(this.btnSo1_Click);
			// 
			// btnSo0
			// 
			this.btnSo0.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo0.Location = new System.Drawing.Point(48, 48);
			this.btnSo0.Name = "btnSo0";
			this.btnSo0.Size = new System.Drawing.Size(32, 24);
			this.btnSo0.TabIndex = 14;
			this.btnSo0.Text = "0";
			this.btnSo0.Click += new System.EventHandler(this.btnSo0_Click);
			// 
			// btnSo00
			// 
			this.btnSo00.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo00.Location = new System.Drawing.Point(48, 72);
			this.btnSo00.Name = "btnSo00";
			this.btnSo00.Size = new System.Drawing.Size(32, 24);
			this.btnSo00.TabIndex = 13;
			this.btnSo00.Text = "00";
			this.btnSo00.Click += new System.EventHandler(this.btnSo00_Click);
			// 
			// btnSo000
			// 
			this.btnSo000.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSo000.Location = new System.Drawing.Point(80, 72);
			this.btnSo000.Name = "btnSo000";
			this.btnSo000.Size = new System.Drawing.Size(64, 24);
			this.btnSo000.TabIndex = 12;
			this.btnSo000.Text = "000";
			this.btnSo000.Click += new System.EventHandler(this.btnSo000_Click);
			// 
			// btnNgoacNhonPhai
			// 
			this.btnNgoacNhonPhai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNgoacNhonPhai.Location = new System.Drawing.Point(368, 24);
			this.btnNgoacNhonPhai.Name = "btnNgoacNhonPhai";
			this.btnNgoacNhonPhai.Size = new System.Drawing.Size(32, 24);
			this.btnNgoacNhonPhai.TabIndex = 11;
			this.btnNgoacNhonPhai.Text = "}";
			this.btnNgoacNhonPhai.Click += new System.EventHandler(this.btnNgoacNhonPhai_Click);
			// 
			// btnNgoacNhonTrai
			// 
			this.btnNgoacNhonTrai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNgoacNhonTrai.Location = new System.Drawing.Point(336, 24);
			this.btnNgoacNhonTrai.Name = "btnNgoacNhonTrai";
			this.btnNgoacNhonTrai.Size = new System.Drawing.Size(32, 24);
			this.btnNgoacNhonTrai.TabIndex = 10;
			this.btnNgoacNhonTrai.Text = "{";
			this.btnNgoacNhonTrai.Click += new System.EventHandler(this.btnNgoacNhonTrai_Click);
			// 
			// btnNgoacVuongPhai
			// 
			this.btnNgoacVuongPhai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNgoacVuongPhai.Location = new System.Drawing.Point(304, 24);
			this.btnNgoacVuongPhai.Name = "btnNgoacVuongPhai";
			this.btnNgoacVuongPhai.Size = new System.Drawing.Size(32, 24);
			this.btnNgoacVuongPhai.TabIndex = 9;
			this.btnNgoacVuongPhai.Text = "]";
			this.btnNgoacVuongPhai.Click += new System.EventHandler(this.btnNgoacVuongPhai_Click);
			// 
			// btnNgoacVuongTrai
			// 
			this.btnNgoacVuongTrai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNgoacVuongTrai.Location = new System.Drawing.Point(272, 24);
			this.btnNgoacVuongTrai.Name = "btnNgoacVuongTrai";
			this.btnNgoacVuongTrai.Size = new System.Drawing.Size(32, 24);
			this.btnNgoacVuongTrai.TabIndex = 8;
			this.btnNgoacVuongTrai.Text = "[";
			this.btnNgoacVuongTrai.Click += new System.EventHandler(this.btnNgoacVuongTrai_Click);
			// 
			// btnNgoacDonPhai
			// 
			this.btnNgoacDonPhai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNgoacDonPhai.Location = new System.Drawing.Point(240, 24);
			this.btnNgoacDonPhai.Name = "btnNgoacDonPhai";
			this.btnNgoacDonPhai.Size = new System.Drawing.Size(32, 24);
			this.btnNgoacDonPhai.TabIndex = 7;
			this.btnNgoacDonPhai.Text = ")";
			this.btnNgoacDonPhai.Click += new System.EventHandler(this.btnNgoacDonPhai_Click);
			// 
			// btnNgoacDonTrai
			// 
			this.btnNgoacDonTrai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNgoacDonTrai.Location = new System.Drawing.Point(208, 24);
			this.btnNgoacDonTrai.Name = "btnNgoacDonTrai";
			this.btnNgoacDonTrai.Size = new System.Drawing.Size(32, 24);
			this.btnNgoacDonTrai.TabIndex = 6;
			this.btnNgoacDonTrai.Text = "(";
			this.btnNgoacDonTrai.Click += new System.EventHandler(this.btnNgoacDonTrai_Click);
			// 
			// btnMu
			// 
			this.btnMu.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnMu.Location = new System.Drawing.Point(176, 24);
			this.btnMu.Name = "btnMu";
			this.btnMu.Size = new System.Drawing.Size(32, 24);
			this.btnMu.TabIndex = 5;
			this.btnMu.Text = "^";
			this.btnMu.Click += new System.EventHandler(this.btnMu_Click);
			// 
			// btnSoDu
			// 
			this.btnSoDu.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSoDu.Location = new System.Drawing.Point(144, 24);
			this.btnSoDu.Name = "btnSoDu";
			this.btnSoDu.Size = new System.Drawing.Size(32, 24);
			this.btnSoDu.TabIndex = 4;
			this.btnSoDu.Text = "%";
			this.btnSoDu.Click += new System.EventHandler(this.btnSoDu_Click);
			// 
			// btnChia
			// 
			this.btnChia.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnChia.Location = new System.Drawing.Point(112, 24);
			this.btnChia.Name = "btnChia";
			this.btnChia.Size = new System.Drawing.Size(32, 24);
			this.btnChia.TabIndex = 3;
			this.btnChia.Text = "/";
			this.btnChia.Click += new System.EventHandler(this.btnChia_Click);
			// 
			// btnNhan
			// 
			this.btnNhan.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnNhan.Location = new System.Drawing.Point(80, 24);
			this.btnNhan.Name = "btnNhan";
			this.btnNhan.Size = new System.Drawing.Size(32, 24);
			this.btnNhan.TabIndex = 2;
			this.btnNhan.Text = "*";
			this.btnNhan.Click += new System.EventHandler(this.btnNhan_Click);
			// 
			// btnTru
			// 
			this.btnTru.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnTru.Location = new System.Drawing.Point(48, 24);
			this.btnTru.Name = "btnTru";
			this.btnTru.Size = new System.Drawing.Size(32, 24);
			this.btnTru.TabIndex = 1;
			this.btnTru.Text = "-";
			this.btnTru.Click += new System.EventHandler(this.btnTru_Click);
			// 
			// btnCong
			// 
			this.btnCong.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnCong.Location = new System.Drawing.Point(16, 24);
			this.btnCong.Name = "btnCong";
			this.btnCong.Size = new System.Drawing.Size(32, 24);
			this.btnCong.TabIndex = 0;
			this.btnCong.Text = "+";
			this.btnCong.Click += new System.EventHandler(this.btnCong_Click);
			// 
			// groupBox5
			// 
			this.groupBox5.Controls.Add(this.btnPhanTich);
			this.groupBox5.Controls.Add(this.btnGiai);
			this.groupBox5.Controls.Add(this.rdbRadian);
			this.groupBox5.Controls.Add(this.rdbDo);
			this.groupBox5.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox5.Location = new System.Drawing.Point(16, 80);
			this.groupBox5.Name = "groupBox5";
			this.groupBox5.Size = new System.Drawing.Size(416, 64);
			this.groupBox5.TabIndex = 4;
			this.groupBox5.TabStop = false;
			// 
			// btnPhanTich
			// 
			this.btnPhanTich.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnPhanTich.Location = new System.Drawing.Point(200, 24);
			this.btnPhanTich.Name = "btnPhanTich";
			this.btnPhanTich.Size = new System.Drawing.Size(104, 24);
			this.btnPhanTich.TabIndex = 3;
			this.btnPhanTich.Text = "Phân tích";
			this.btnPhanTich.Click += new System.EventHandler(this.btnPhanTich_Click);
			// 
			// btnGiai
			// 
			this.btnGiai.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnGiai.Location = new System.Drawing.Point(320, 24);
			this.btnGiai.Name = "btnGiai";
			this.btnGiai.Size = new System.Drawing.Size(80, 24);
			this.btnGiai.TabIndex = 2;
			this.btnGiai.Text = "Giải";
			this.btnGiai.Click += new System.EventHandler(this.btnGiai_Click);
			// 
			// rdbRadian
			// 
			this.rdbRadian.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.rdbRadian.Location = new System.Drawing.Point(104, 24);
			this.rdbRadian.Name = "rdbRadian";
			this.rdbRadian.Size = new System.Drawing.Size(88, 24);
			this.rdbRadian.TabIndex = 1;
			this.rdbRadian.Text = "Radian";
			this.rdbRadian.CheckedChanged += new System.EventHandler(this.rdbRadian_CheckedChanged);
			// 
			// rdbDo
			// 
			this.rdbDo.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.rdbDo.Location = new System.Drawing.Point(16, 24);
			this.rdbDo.Name = "rdbDo";
			this.rdbDo.Size = new System.Drawing.Size(80, 24);
			this.rdbDo.TabIndex = 0;
			this.rdbDo.Text = "Độ";
			this.rdbDo.CheckedChanged += new System.EventHandler(this.rdbDo_CheckedChanged);
			// 
			// txtKetQua
			// 
			this.txtKetQua.Location = new System.Drawing.Point(16, 56);
			this.txtKetQua.Name = "txtKetQua";
			this.txtKetQua.ReadOnly = true;
			this.txtKetQua.Size = new System.Drawing.Size(416, 22);
			this.txtKetQua.TabIndex = 3;
			this.txtKetQua.Text = "";
			// 
			// txtGoBieuThuc
			// 
			this.txtGoBieuThuc.Location = new System.Drawing.Point(16, 24);
			this.txtGoBieuThuc.Name = "txtGoBieuThuc";
			this.txtGoBieuThuc.Size = new System.Drawing.Size(416, 22);
			this.txtGoBieuThuc.TabIndex = 2;
			this.txtGoBieuThuc.Text = "";
			// 
			// groupBox3
			// 
			this.groupBox3.Controls.Add(this.lbHam);
			this.groupBox3.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.groupBox3.Location = new System.Drawing.Point(488, 16);
			this.groupBox3.Name = "groupBox3";
			this.groupBox3.Size = new System.Drawing.Size(112, 344);
			this.groupBox3.TabIndex = 2;
			this.groupBox3.TabStop = false;
			// 
			// lbHam
			// 
			this.lbHam.ItemHeight = 16;
			this.lbHam.Items.AddRange(new object[] {
													   "abs()",
													   "acos()",
													   "asin()",
													   "atan()",
													   "cos()",
													   "cosh()",
													   "exp()",
													   "log()",
													   "logn()",
													   "ln()",
													   "sin()",
													   "sinh()",
													   "sqrt()",
													   "tan()",
													   "tanh()"});
			this.lbHam.Location = new System.Drawing.Point(16, 24);
			this.lbHam.Name = "lbHam";
			this.lbHam.Size = new System.Drawing.Size(80, 292);
			this.lbHam.TabIndex = 0;
			// 
			// MayTinhBieuThuc
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 15);
			this.ClientSize = new System.Drawing.Size(634, 488);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.groupBox1);
			this.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "MayTinhBieuThuc";
			this.Text = "May tinh bieu thuc";
			this.Load += new System.EventHandler(this.Form1_Load);
			this.groupBox1.ResumeLayout(false);
			this.groupBox2.ResumeLayout(false);
			this.groupBox4.ResumeLayout(false);
			this.groupBox6.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.m_symTable)).EndInit();
			this.groupBox5.ResumeLayout(false);
			this.groupBox3.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion


		private void Form1_Load(object sender, System.EventArgs e)
		{
			this.rdbDo.Select();
			this.btnGiai.Enabled = false;
		}


		private void btnCong_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "+";
		}

		private void btnTru_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "-";
		}

		private void btnNhan_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "*";
		}

		private void btnChia_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "/";
		}

		private void btnSoDu_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "%";
		}

		private void btnMu_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "^";
		}

		private void btnNgoacDonTrai_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "(";
		}

		private void btnNgoacDonPhai_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += ")";
		}

		private void btnNgoacVuongTrai_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "[";
		}

		private void btnNgoacVuongPhai_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "]";
		}

		private void btnNgoacNhonTrai_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "{";
		}

		private void btnNgoacNhonPhai_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "}";
		}

		private void btnSo0_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "0";
		}

		private void btnSo1_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "1";
		}

		private void btnSo2_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "2";
		}

		private void btnSo3_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "3";
		}

		private void btnSo4_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "4";
		}

		private void btnSo5_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "5";
		}

		private void btnSo6_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "6";
		}

		private void btnSo7_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "7";
		}

		private void btnSo8_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "8";
		}

		private void btnSo9_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "9";
		}

		private void btnDauChamThapPhan_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += ".";
		}

		private void btnSo00_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "00";
		}

		private void btnSo000_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "000";
		}

		private void btnPi_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "3.1415926535897932384626433832795";
		}

		private void btnE_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Text += "e";
		}

		private void btnXoaHet_Click(object sender, System.EventArgs e)
		{
			this.txtGoBieuThuc.Clear();
		}

		private void btnThem_Click(object sender, System.EventArgs e)
		{
			switch (lbHam.SelectedIndex)
			{
				case 0:
					this.txtGoBieuThuc.Text += "abs(";
					break;

				case 1:
					this.txtGoBieuThuc.Text += "acos(";
					break;

				case 2:
					this.txtGoBieuThuc.Text += "asin(";
					break;

				case 3:
					this.txtGoBieuThuc.Text += "atan(";
					break;

				case 4:
					this.txtGoBieuThuc.Text += "cos(";
					break;

				case 5:
					this.txtGoBieuThuc.Text += "cosh(";
					break;

				case 6:
					this.txtGoBieuThuc.Text += "exp(";
					break;

				case 7:
					this.txtGoBieuThuc.Text += "log(";
					break;

				case 8:
					this.txtGoBieuThuc.Text += "logn(";
					break;

				case 9:
					this.txtGoBieuThuc.Text += "ln(";
					break;

				case 10:
					this.txtGoBieuThuc.Text += "sin(";
					break;

				case 11:
					this.txtGoBieuThuc.Text += "sinh(";
					break;

				case 12:
					this.txtGoBieuThuc.Text += "sqrt(";
					break;

				case 13:
					this.txtGoBieuThuc.Text += "tan(";
					break;

				case 14:
					this.txtGoBieuThuc.Text += "tanh(";
					break;
			}
		}


		private void btnPhanTich_Click(object sender, System.EventArgs e)
		{
			try
			{
				fn.Parse(this.txtGoBieuThuc.Text);
				fn.Infix2Postfix();
				ArrayList var = fn.Variables;
				DataRow row;
				m_table.Rows.Clear();
				foreach(Symbol sym in var)
				{
					row = m_table.NewRow();
					row["Ten"] = sym.m_name;
					row["Gia tri"] = sym.m_value;
					m_table.Rows.Add(row);
				}
				m_symTable.SetDataBinding(m_dataSet,"Variable");
				this.btnGiai.Enabled = true;
			}
			catch (Exception ex)
			{
				MessageBox.Show("Đã có lỗi xảy ra! Các bạn hãy kiểm tra lại xem mình đã thao tác đúng chưa nhé!",ex.Source);
			}
		}


		private void btnGiai_Click(object sender, System.EventArgs e)
		{
			//			if(!bParsed)
			//			{
			//				MessageBox.Show("Bạn hãy kích chuột vào nút Phân tích trước nhé!");
			//				return;
			//			}
		
			try
			{
				ArrayList var = new ArrayList();
				Symbol sym;
				foreach(DataRow row in m_table.Rows)
				{
					sym.m_name = (string)row["Ten"];
					sym.m_value = (double)row["Gia tri"];
					sym.m_type = EB.Math.Type.Variable;
					var.Add(sym);
				}
				fn.Variables = var;
				fn.DefaultFunctionEvaluation = new EvaluateFunctionDelegate(EvaluateFnc);
				fn.EvaluatePostfix();
				if(fn.Error)
				{
					MessageBox.Show(fn.ErrorDescription);
					return;
				}
				this.txtKetQua.Text = fn.Result.ToString(); 
				if(this.txtKetQua.Text != null)
				{
					this.btnGiai.Enabled = false;
				}
			}
			catch (Exception ex)
			{
				MessageBox.Show("Đã có lỗi xảy ra! Các bạn hãy kiểm tra lại xem mình đã thao tác đúng chưa nhé!",ex.Source);
			}
		}


		public Symbol EvaluateFnc(string name, params Object[] args)
		{
			Symbol result;
			result.m_name = "";
			result.m_type = EB.Math.Type.Result;
			result.m_value = 0;
			switch(name)
			{
				case "add":
					if(args.Length == 2)
					{
						result.m_name = name + "(" + ((Symbol)args[0]).m_value.ToString() + ")";
						result.m_value = ((Symbol)args[0]).m_value + ((Symbol)args[1]).m_value;
					}
					else 
					{
						result.m_name = "Tham số không hợp lệ: "+ name +".";
						result.m_type = EB.Math.Type.Error;
					}
					break;
				default:
				{
					result.m_name = "Hàm: "+ name +", không tìm thấy.";
					result.m_type = EB.Math.Type.Error;
				}
					break;
			}
			return result;
		}


		private void rdbDo_CheckedChanged(object sender, System.EventArgs e)
		{
			Y_Function.blnDo = this.rdbDo.Checked;
		}

		private void rdbRadian_CheckedChanged(object sender, System.EventArgs e)
		{
			Y_Function.blnRadian = this.rdbRadian.Checked;
		}


		private void btnThongTin_Click(object sender, System.EventArgs e)
		{
			Y_ThongTinMayTinh frmThongTin = new Y_ThongTinMayTinh();
			frmThongTin.Show();
		}
	}
}
